package com.wl.jetpackdemo.bottomtab

import android.content.Intent
import android.os.Bundle
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.wl.jetpackdemo.R
import com.wl.jetpackdemo.base.BaseActivity
import com.wl.jetpackdemo.base.BaseViewModel
import com.wl.jetpackdemo.databinding.ActivityBottomTabLayoutBinding
import com.wl.jetpackdemo.chat.MessageMainActivity
import java.util.ArrayList

class BottomTabLayoutActivity : BaseActivity() {
    private lateinit var binding: ActivityBottomTabLayoutBinding
    private val titles = listOf("推荐", "派对", "消息", "我的")
    private val selectIcons = listOf(R.drawable.index_select, R.drawable.party_select, R.drawable.message_select, R.drawable.me_select)
    private val unSelectIcons = listOf(R.drawable.index, R.drawable.party, R.drawable.message, R.drawable.me)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityBottomTabLayoutBinding.inflate(layoutInflater)
        setContentView(binding.root)

        var tabEntities = ArrayList<CustomTabEntity>()
        for (i in titles.indices) {
            tabEntities.add(TabEntity(titles[i], selectIcons[i], unSelectIcons[i]))
        }

        binding.bottomTab.setTabData(tabEntities)

        binding.bottomTab.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                //处理tab项跳转至新Activity的逻辑
                if (position == AdapterFragmentPager.PAGE_MESSAGE) {
                    binding.bottomTab.currentTab = binding.vpContainer.currentItem
                    startActivity(Intent(this@BottomTabLayoutActivity, MessageMainActivity::class.java))
                } else {
                    binding.vpContainer.setCurrentItem(position, false)
                }
            }

            override fun onTabReselect(position: Int) {
            }
        })

        binding.bottomTab.showMsg(2, 100)

        binding.vpContainer.adapter = AdapterFragmentPager(this)
        binding.vpContainer.offscreenPageLimit = 1
        binding.vpContainer.isUserInputEnabled = false
    }

    override fun generateViewModel(): BaseViewModel? {
        return null
    }

    override fun getStatusBarColor(): Int {
        return resources.getColor(R.color.white)
    }
}